package net.lab1024.smartadmin.module.business.drivingCycle.service;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import net.lab1024.smartadmin.common.domain.PageResultDTO;
import net.lab1024.smartadmin.common.domain.ResponseDTO;
import net.lab1024.smartadmin.module.business.drivingCycle.dao.DrivingCycleDao;
import net.lab1024.smartadmin.module.business.drivingCycle.domain.dto.DrivingCycleAddDTO;
import net.lab1024.smartadmin.module.business.drivingCycle.domain.dto.DrivingCycleQueryDTO;
import net.lab1024.smartadmin.module.business.drivingCycle.domain.dto.DrivingCycleUpdateDTO;
import net.lab1024.smartadmin.module.business.drivingCycle.domain.entity.DrivingCycleEntity;
import net.lab1024.smartadmin.module.business.drivingCycle.domain.vo.DrivingCycleExcelVO;
import net.lab1024.smartadmin.module.business.drivingCycle.domain.vo.DrivingCycleVO;
import net.lab1024.smartadmin.util.SmartBeanUtil;
import net.lab1024.smartadmin.util.SmartPageUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * [ ��ʻ������������ ]
 *
 * @author wuhq
 * @version 1.0
 * @company ��������
 * @copyright (c)  ��������Inc. All rights reserved.
 * @date 2021-11-19 11:22:47
 * @since JDK1.8
 */
@Service
public class DrivingCycleService {

    @Autowired
    private DrivingCycleDao drivingCycleDao;

    /**
     * ����id��ѯ
     */
    public DrivingCycleVO getById(Long id){
        return  drivingCycleDao.getById(id);
    }

    /**
     * ��ҳ��ѯ
     * @author wuhq
     * @date 2021-11-19 11:22:47
     */
    public ResponseDTO<PageResultDTO<DrivingCycleVO>> queryByPage(DrivingCycleQueryDTO queryDTO) {
        Page page = SmartPageUtil.convert2QueryPage(queryDTO);
        IPage<DrivingCycleVO> voList = drivingCycleDao.queryByPage(page, queryDTO);
        PageResultDTO<DrivingCycleVO> pageResultDTO = SmartPageUtil.convert2PageResult(voList);
        return ResponseDTO.succData(pageResultDTO);
    }

    /**
     * ���
     * @author wuhq
     * @date 2021-11-19 11:22:47
     */
    public ResponseDTO<String> add(DrivingCycleAddDTO addDTO) {
        DrivingCycleEntity entity = SmartBeanUtil.copy(addDTO, DrivingCycleEntity.class);
        drivingCycleDao.add(entity);
        return ResponseDTO.succ();
    }

    /**
     * �༭
     * @author wuhq
     * @date 2021-11-19 11:22:47
     */
    @Transactional(rollbackFor = Exception.class)
    public ResponseDTO<String> update(DrivingCycleUpdateDTO updateDTO) {
        DrivingCycleEntity entity = SmartBeanUtil.copy(updateDTO, DrivingCycleEntity.class);
        drivingCycleDao.update(entity);
        return ResponseDTO.succ();
    }

    /**
     * ɾ��
     * @author wuhq
     * @date 2021-11-19 11:22:47
     */
    @Transactional(rollbackFor = Exception.class)
    public ResponseDTO<String> deleteByIds(List<Long> idList) {
        drivingCycleDao.deleteByIdList(idList);
        return ResponseDTO.succ();
    }

    /**
     * ��ѯȫ����������
     * @author wuhq
     * @date 2021-11-19 11:22:47
     */
    public List<DrivingCycleExcelVO> queryAllExportData(DrivingCycleQueryDTO queryDTO) {
        return drivingCycleDao.queryAllExportData( queryDTO);
    }

    /**
     * ������ѯ��������
     * @author wuhq
     * @date 2021-11-19 11:22:47
     */
    public List<DrivingCycleExcelVO> queryBatchExportData(List<Long> idList) {
        return drivingCycleDao.queryBatchExportData(idList);
    }
}
